
var pageContext = new PageContext(settings||{});

pageContext.back = function(target){
	var $lis = $("#page-header>ul>li");
	var len = $lis.length ;
	$($lis.get(len-2)).find("a").click();
}
pageContext.addItemAfter = function(result,para){
	pageContext.back();
};
pageContext.updateItemAfter = function(result,para){
	pageContext.back();
};
pageContext.formInit = function(layero){
	
} 
pageContext.init = function(){//初始化
	pageContext.initEvent();
};
jQuery(function($) {
	 $(document).find("input").each(function(){
		 $(this).attr("autocomplete","off");
	 });
	$('#homeAddress').citys({
	dataUrl:window.global.ctx+"/static/fw/plugin/data_location/list.json?noPage=1"
	 ,code:$("#applyeditForm").find("select[name='a.provinceCode']").attr("value")
	 ,province:$("#applyeditForm").find("select[name='a.provinceCode']").attr("value")             
     ,city:$("#applyeditForm").find("select[name='a.cityCode']").attr("value")         
     ,area:$("#applyeditForm").find("select[name='a.districtCode']").attr("value")
	 ,provinceField:'a.provinceCode' //省份字段名
     ,cityField:'a.cityCode'         //城市字段名
     ,areaField:'a.districtCode'         //地区字段名
	 ,required:false
	,onChange:function(me,info){
		if(me!=null){
		   var p = $(me).attr("prefix");
		   if(p && p!=""){
			   var val = $(me).find("option:selected").val();
			   var text = "";
			   if(val!=""){
				   text = $(me).find("option:selected").text();
			   }
			   $('#applyeditForm input[name="'+p+'Name"]').val(text).change();
		   }
		   var $span =   $(me).css("width", "auto").hide().next("span");
		   var size = $(me).find("option").length;
		   if(size>0){
			   $span.show();
		   }else{
			   $span.hide();
		   }
		   $span.css("width", ($(me).outerWidth()+40)+"px"); 
		}
	},onReady:function(){
		$('#homeAddress').find('select[novalid="true"]').each(function(){
			$(this).hide().width("auto")
            .css("width", "auto").css("min-width", "80px").select2({
	            language: "zh-CN"}).removeClass("select2-hidden-accessible");
			
		})
	}});
	$('#currentAddress').citys({
		dataUrl:window.global.ctx+"/static/fw/plugin/data_location/list.json?noPage=1"
		 ,code:$("#applyeditForm").find("select[name='c.provinceCode']").attr("value")
		 ,province:$("#applyeditForm").find("select[name='c.provinceCode']").attr("value")             
	     ,city:$("#applyeditForm").find("select[name='c.cityCode']").attr("value")         
	     ,area:$("#applyeditForm").find("select[name='c.districtCode']").attr("value")
		 ,provinceField:'c.provinceCode' //省份字段名
	     ,cityField:'c.cityCode'         //城市字段名
	     ,areaField:'c.districtCode'         //地区字段名
	     ,required:false
		,onChange:function(me,info){
			if(me!=null){
			   var p = $(me).attr("prefix");
			   if(p && p!=""){
				   var val = $(me).find("option:selected").val();
				   var text = "";
				   if(val!=""){
					   text = $(me).find("option:selected").text();
				   }
				   $('#applyeditForm input[name="'+p+'Name"]').val(text).change();
			   }
			   var $span =   $(me).css("width", "auto").hide().next("span");
			   var size = $(me).find("option").length;
			   if(size>0){
				   $span.show();
			   }else{
				   $span.hide();
			   }
			   $span.css("width", ($(me).outerWidth()+40)+"px"); 
			}
		},onReady:function(){
			$('#currentAddress').find('select[novalid="true"]').each(function(){
				$(this).hide().width("auto")
	            .css("width", "auto").css("min-width", "80px").select2({
		            language: "zh-CN"}).removeClass("select2-hidden-accessible");
				
			})
		}});
	

	$(".home").on("change",function(){
		var map = new Map();
		$(".home").each(function(){
			map.put($(this).attr("index"),$(this).val());
		});
		var index = 1;
		var $input = $('#applyeditForm input[name="a.address"]');
		var str = "";
		while(index<=4){
			var v = map.get(index);
			if(v!=null && v!=undefined){
				str+=v;
			}
			index++;
		}
		$input.val(str);
	});
	$(".current").on("change",function(){
		var map = new Map();
		$(".current").each(function(){
			map.put($(this).attr("index"),$(this).val());
		});
		var index = 1;
		var $input = $('#applyeditForm input[name="c.address"]');
		var str = "";
		while(index<=4){
			var v = map.get(index);
			if(v!=null && v!=undefined){
				str+=v;
			}
			index++;
		}
		$input.val(str);
	});
	
	
	$("#applyeditForm .inputElem").mailAutoComplete({height:"100px"});
   pageContext.init({});
   $('#applyeditForm select[novalid!="true"]').on("change",function(){
	   var me = this;
	   var p = $(me).attr("prefix");
	   if(p && p!=""){
		   var val = $(me).find("option:selected").val();
		   var text = "";
		   if(val!=""){
			   text = $(me).find("option:selected").text();
		   }
		   $('#applyeditForm input[name="'+p+'Name"]').val(text).change();
	   }
   })
   var layero = $("#applyeditForm");
	layero.find('select[novalid!="true"]').each(function(){
		var novalid = $(this).attr("noconvert");
		if(novalid!="true"){
			layero.find(this).select2({
	            language: "zh-CN",width:"off"})
	            .next("span").removeClass("col-xs-10-select2").addClass("col-xs-10-select2");
		}
	  });
   $('#applyeditForm select').change();
	var form =  $("#"+pageContext.setting.formId);
	form.validationEngine('attach', {promptPosition : "topLeft", autoPositionUpdate : true});
	pageInit();
}); 
